Skip to content

gh-160522: Restore CJK encoder state after a failed incremental encode - #160523

Open
gpshead wants to merge 1 commit into
python:mainfrom
gpshead:scanfix-multibytecodec-zdf903iu
Open

gpshead wants to merge 1 commit into
python:mainfrom
gpshead:scanfix-multibytecodec-zdf903iu

Conversation

@gpshead

@gpshead gpshead commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

encoder_encode_stateful() now saves the codec state on entry and puts it back when the call fails, as it already did for its pending buffer. A failed call discards its output, so keeping the state it reached made the next IncrementalEncoder.encode() or StreamWriter.write() skip the escape sequence. The decoders are not changed: they keep the state reached before the error, which is right for a caller that goes on with the following bytes of the same stream.

Fixes #160522

ANT-2026-ZDF903IU

… encode

A failed IncrementalEncoder.encode() or StreamWriter.write() of a
stateful CJK codec kept the shift state reached before the error
although its output was discarded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes sprint

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Stateful CJK incremental encoders keep the shift state after a failed encode()

1 participant